﻿using System.Security.Claims;

namespace Admin.Crypto.Session
{
    public interface IPrincipalAccessor
    {
        /// <summary>
        /// 声明主体
        /// </summary>
        ClaimsPrincipal Principal { get; }
    }

    /// <summary>
    /// 基于声明主体访问默认实现
    /// </summary>
    public class DefaultPrincipalAccessor : IPrincipalAccessor
    {
        /// <summary>
        /// 获取声明主体
        /// </summary>
        public virtual ClaimsPrincipal Principal => Thread.CurrentPrincipal as ClaimsPrincipal;

        /// <summary>
        /// 静态实例化
        /// </summary>
        public static DefaultPrincipalAccessor Instance => new DefaultPrincipalAccessor();
    }
}
